package com.chukun.multi.producerconsumer;

import java.util.concurrent.BlockingQueue;

/**
 * @author chukun
 *  基于阻塞队列实现的通道
 * @param <P>
 */
public class BlockingQueueProductChannel<P> implements ProductChannel<P> {

    private final BlockingQueue<P> blockingQueue;

    public BlockingQueueProductChannel(BlockingQueue<P> blockingQueue) {
        this.blockingQueue = blockingQueue;
    }

    @Override
    public P take() throws InterruptedException {
        return blockingQueue.take();
    }

    @Override
    public void put(P product) throws InterruptedException {
         blockingQueue.put(product);
    }
}
